<template>
  <div>
    <!--基本信息-->
    <div style="font-size:24px">
      <span>基本信息</span>
      <a-card style="margin: 10px 0;">
        <a-form-model :label-col="labelCol" :wrapper-col="wrapperCol" ref="ruleForm">
          <a-row>
            <a-col :span="6">
              <a-form-model-item label="计划编号">
                <a-input v-model="form.planCode" placeholder="请输入" :disabled=true />
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="计划名称">
                <a-input v-model="form.planName" placeholder="请输入" :disabled=true />
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="考核类型">
                <a-input v-model="form.assessmentType" placeholder="请输入" :disabled=true />
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="年/季/月">
                <a-input v-model="form.year" placeholder="请输入" :disabled=true />
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col :span="6">
              <a-form-model-item label="是否允许分发">
                <a-input v-model="form.year" placeholder="请输入" :disabled=true />
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="考核对象">
                <a-input v-model="form.assessmentUser" placeholder="请输入" :disabled=true />
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="考核周期">
                <a-input v-model="form.assessmentCycle" placeholder="请输入" :disabled=true />
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="创建时间">
                <a-input v-model="form.createTime" placeholder="请输入" :disabled=true />
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
      </a-card>
    </div>
    <!--方案信息-->
    <div style="font-size:24px">
      <span>方案信息</span>
      <a-card style="margin: 10px 0;">
        <a-form-model :label-col="labelCol" :wrapper-col="wrapperCol" ref="ruleForm">
          <a-row>
            <a-col :span="6">
              <a-form-model-item label="方案编码">
                <a-input v-model="form.schemeCode" placeholder="请输入" :disabled=true />
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="方案名称">
                <a-input v-model="form.schemeName" placeholder="请输入" :disabled=true />
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="适用范围">
                <a-input v-model="form.scope" placeholder="请输入" :disabled=true />
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="是否有效">
                <a-input v-model="form.status" placeholder="请输入" :disabled=true />
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col :span="6">
              <a-form-model-item label="考核部门">
                <a-input v-model="form.assessmentDepart" placeholder="请输入" :disabled=true />
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="复核部门">
                <a-input v-model="form.reviewDepart" placeholder="请输入" :disabled=true />
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="终审部门">
                <a-input v-model="form.finalDepart" placeholder="请输入" :disabled=true />
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="是否启用总分控制">
                <a-input v-model="form.totalScoreFlag" placeholder="请输入" :disabled=true />
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col :span="6">
              <a-form-model-item label="总分">
                <a-input v-model="form.totalScore" placeholder="请输入" :disabled=true />
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="创建人">
                <a-input v-model="form.schemeCreateBy" placeholder="请输入" :disabled=true />
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="创建时间">
                <a-input v-model="form.schemeCreateTime" placeholder="请输入" :disabled=true />
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col :span="12" class="textItem1">
              <a-form-model-item label="方案说明">
                <a-textarea v-model="form.remark" placeholder="请输入" :auto-size="{ minRows: 4, maxRows: 6 }" :disabled=true />
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
      </a-card>
    </div>
    <!--复议申请信息-->
    <div style="font-size:24px">
      <span>复议申请信息</span>
      <a-card style="margin: 10px 0;">
        <a-form-model :label-col="labelCol" :wrapper-col="wrapperCol" ref="ruleForm">
          <a-row>
            <a-col :span="6">
              <a-form-model-item label="考核总分">
                <a-input v-model="form.assessmentScore" placeholder="请输入" :disabled='applyInfoDisabled'/>
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="复议分数">
                <a-input v-model="form.reconsiderationScore" placeholder="请输入" :disabled='applyInfoDisabled'/>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row v-if="componentName === 'examCheck'" >
            <a-col :span="6">
              <a-form-model-item label="复议状态">
                <a-input v-model="form.reconsiderationType" placeholder="请输入" :disabled=true />
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col :span="12" class="textItem1">
              <a-form-model-item label="复议缘由">
                <a-textarea v-model="form.reconsiderationReason" placeholder="请输入" :disabled='applyInfoDisabled' :auto-size="{ minRows: 1, maxRows: 6 }" />
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row v-if="componentName === 'reviewApply'">
            <a-col :span="6">
              <a-form-model-item :wrapper-col="{ offset: 0 }" style="margin-bottom: 0">
                <a-button @click="clickCancel"> 取消</a-button>
                <a-button type="primary" style="margin: 0 10px" @click="clickSave" v-if="fuyiStatus === '1' || fuyiStatus === '4'"> 保存 </a-button>
                <a-button @click="onSubmit" v-if="fuyiStatus === '1' || fuyiStatus === '4'"> 提交</a-button>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row v-if="componentName === 'myReviewExamine' && (fuyiStatus === '1' || fuyiStatus === '4')">
            <a-col :span="6">
              <a-form-model-item :wrapper-col="{ offset: 0 }" style="margin-bottom: 0">
                <a-button @click="clickCancel2"> 取消</a-button>
                <a-button type="primary" style="margin: 0 10px" @click="onSubmit"> 确认 </a-button>
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
      </a-card>
    </div>
    <!--复议审核信息-->
    <div style="font-size:24px" v-if="componentName === 'examCheck'" >
      <span>复议审核信息</span>
      <a-card style="margin: 10px 0;">
        <a-form-model :label-col="labelCol" :wrapper-col="wrapperCol" ref="ruleForm" :model="form" :rules="rules">
          <a-row>
            <a-col :span="6">
              <a-form-model-item label="审核状态">
                <a-input v-model="form.reconsiderationTypeName"  disabled=true />
                <!--<a-select v-model="form.reconsiderationType" placeholder="请选择" style="width:100%;" allowClear>
                  <a-select-option v-for="(item, key) in reconsiderationType" :key="key" :value="item.value">{{ item.title }}
                  </a-select-option>
                </a-select>-->
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col :span="12" class="textItem1">
              <a-form-model-item label="审核意见">
                <a-textarea v-model="form.reconExamineReason" placeholder="请输入" :auto-size="{ minRows: 1, maxRows: 6 }" style="width: 100%"/>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row v-if="fuyiStatus ==='1' || fuyiStatus ==='2'">
            <a-col :span="4">
              <a-form-model-item :wrapper-col="{ offset: 0 }" style="margin-bottom: 0">
                <a-button @click="ondisagree"> 拒绝</a-button>
                <a-button type="primary" style="margin-left: 10px" @click="onAgree"> 通过 </a-button>
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
      </a-card>
    </div>
  </div>

</template>

<script>
  import { getDictItemsFromCache } from '@/api/api'
  import Api from '@/api/sjsk/performanceServiceQuery'

  export default {
    name: "selfExamine",
    components: {},
    data() {
      return {
        labelCol: { span: 6 },
        wrapperCol: { span: 17 },
        form: {},
        rules: {},
        loading: false,
        componentName:'reviewApply',
        applyInfoDisabled:false,
        reconsiderationType: getDictItemsFromCache('reconsiderationType'),
        fuyiStatus:''
      }
    },
    created(){
      this.componentName = this.$route.query.type
      this.fuyiStatus = this.$route.query.fuyiStatus
      if(this.componentName === 'reviewApply' || (this.componentName === 'myReviewExamine' && (this.fuyiStatus === '1' || this.fuyiStatus === '4'))){
        this.applyInfoDisabled = false
      }else{
        this.applyInfoDisabled = true;
      }
      console.info('this.componentName',this.componentName)
      this.getDetail()
    },
    methods: {
      getDetail(){
        let form = {
          id:this.$route.query.id,
        }
        this.loading = true
        let interfaceMethod = null;
        if(this.componentName === 'reviewApply'){
          interfaceMethod = Api.appleAssessmentDetail
        }else if(this.componentName === 'examCheck'){
          interfaceMethod = Api.auditAssessmentDetail
        }else{
          interfaceMethod = Api.mineAssessmentDetail
        }
        interfaceMethod(form)
          .then((res) => {
            if (res.success) {
              this.form = res.result;
              if(this.form.reconsiderationType){
                this.form.reconsiderationTypeName = this.$filterDictTextByCache('reviewStatus', this.form.reconsiderationType)
              }
            } else {
              this.$message.error(res.message)
            }
          })
          .finally(() => {
            this.loading = false
          })
      },
      clickCancel() {
        this.$router.back()
      },
      clickCancel2(){
        let that = this;
        this.$confirm({
          title: `是否保存最新修改的内容?`,
          okText: "确认",
          okType: "danger",
          cancelText: "取消",
          onOk() {
            that.clickSave()
          },
          onCancel() {
            that.$router.back()
          },
        });
      },
      // 提交
      onSubmit() {
        if(!this.form.assessmentScore){
          return this.$message.warning('请输入考核得分')
        }
        if(!this.form.reconsiderationScore){
          return this.$message.warning('请输入复议分数')
        }
        if(!this.form.reconsiderationReason){
          return this.$message.warning('请输入复议缘由')
        }
        let params = {
          ...this.form,
        }
        Api.appleAssessmentSubmit(params)
          .then((res) => {
            if (res.success) {
              this.$message.success(res.message)
              this.$router.back()
            } else {
              this.$message.error(res.message)
            }
          })
          .finally(() => {
            this.loading = false
          })
      },
      // 保存
      clickSave() {
        if(!this.form.assessmentScore){
          return this.$message.warning('请输入考核得分')
        }
        if(!this.form.reconsiderationScore){
          return this.$message.warning('请输入复议分数')
        }
        if(!this.form.reconsiderationReason){
          return this.$message.warning('请输入复议缘由')
        }
        let params = {
          ...this.form,
        }
        Api.appleAssessmentSave(params)
          .then((res) => {
            if (res.success) {
              this.$message.success(res.message)
              this.$router.back()
            } else {
              this.$message.error(res.message)
            }
          })
          .finally(() => {
            this.loading = false
          })
      },
      ondisagree(){
        if(!this.form.reconExamineReason){
          return this.$message.warning('请输入审核意见')
        }
        let params = {
          ...this.form,
        }
        Api.mineAssessmentDisAgree(params)
          .then((res) => {
            if (res.success) {
              this.$message.success(res.message)
              this.$router.back()
            } else {
              this.$message.error(res.message)
            }
          })
          .finally(() => {
            this.loading = false
          })
      },
      onAgree(){
        if(!this.form.reconExamineReason){
          return this.$message.warning('请输入审核意见')
        }
        let params = {
          ...this.form,
        }
        Api.mineAssessmentAgree(params)
          .then((res) => {
            if (res.success) {
              this.$message.success(res.message)
              this.$router.back()
            } else {
              this.$message.error(res.message)
            }
          })
          .finally(() => {
            this.loading = false
          })
      }
    }
  }
</script>
<style lang="less" scoped>
  .textItem1{
    width: 100%;
    /deep/.ant-col-6 {
      width: 6.5%;
      // text-align: left;
    }
    /deep/.ant-col-17 {
      width: 50%;
      text-align: left;
    }
  }
</style>